package com.xs.shop.user.service.service.impl;

import com.xs.shop.user.model.entity.AdminInfo;
import com.xs.shop.user.model.entity.Role;
import com.xs.shop.user.service.handlers.BaseContextHandler;
import com.xs.shop.user.service.mapper.AdminInfoMapper;
import com.xs.shop.user.service.service.AdminInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xs.shop.user.model.vo.AdminInfoVO;
import com.xs.shop.user.service.service.RoleService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xs
 * @since 2025-07-15
 */
@Slf4j
@Service
public class AdminInfoServiceImpl extends ServiceImpl<AdminInfoMapper, AdminInfo> implements AdminInfoService {

    @Resource
    private RoleService roleService;

    @Override
    public AdminInfoVO info() {
        Long id = BaseContextHandler.get();
        log.info("id:{}",id);
        AdminInfo adminInfo = this.getById(id);
        AdminInfoVO adminInfoVO = new AdminInfoVO();
        adminInfoVO.setName(adminInfo.getNickname());
        adminInfoVO.setAvatar(adminInfo.getAvatar());
        adminInfoVO.setEmail(adminInfo.getEmail());
        //roleid转换名称
        Role role = this.roleService.getRoleByAdminId(id);
        adminInfoVO.setRole(role.getRoleName());
        return adminInfoVO;
    }
}
